<div class="screenlet" id="findOrdersList">
  <div class="screenlet-title-bar">
    <ul>
      <li class="h3">Order(s) Found</li>
    </ul>
    <br class="clear">
  </div>
  <div class="screenlet-body">
		<form name="massOrderChangeForm" method="post" action="javascript:void();">
	      <div>&nbsp;</div>
	      <table class="basic-table hover-bar" cellspacing='0'>
	        <tr class="header-row">
	           <td width="20%">${uiLabelMap.PartyName}</td>
	          <td width="5%">${uiLabelMap.OrderOrderId}</td>
	         <td width="10%" align="right">Order Date</td>
	          <td width="5%" align="right">${uiLabelMap.OrderItemsOrdered}</td>
	          <td align="right">Shipping Address</td>
	          
	          <td width="10%" align="right">${uiLabelMap.OrderOrderTotal}</td>
	          
	            <#if (requestParameters.filterInventoryProblems?default("N") == "Y") || (requestParameters.filterPOsOpenPastTheirETA?default("N") == "Y") || (requestParameters.filterPOsWithRejectedItems?default("N") == "Y") || (requestParameters.filterPartiallyReceivedPOs?default("N") == "Y")>
	              <td width="15%">${uiLabelMap.CommonStatus}</td>
	              <td width="5%">${uiLabelMap.CommonFilter}</td>
	            <#else>
	              <td width="20%">${uiLabelMap.CommonStatus}</td>
	            </#if>
	          <td width="5%">${uiLabelMap.PartyPartyId}</td>
	          <td width="1%">
	          </td>
	          <td width="10%">&nbsp;</td>
	        </tr>
	        <#if combineableOrderList?has_content>
	          <#assign alt_row = false>
	          	<#list combineableOrderList as combineableOrderInfo>
		          <#list combineableOrderInfo.orderList as orderInfo>
		          	<#assign orderHeader = orderInfo.getDelegator().findByPrimaryKey("OrderHeader", {"orderId": orderInfo.orderId})>
		            <#assign orh = Static["org.ofbiz.order.order.OrderReadHelper"].getHelper(orderHeader)>
		            <#assign statusItem = orderHeader.getRelatedOneCache("StatusItem")>
		            <#assign orderType = orderHeader.getRelatedOneCache("OrderType")>
		            <#if orderType.orderTypeId == "PURCHASE_ORDER">
		              <#assign displayParty = orh.getSupplierAgent()?if_exists>
		            <#else>
		              <#assign displayParty = orh.getPlacingParty()?if_exists>
		            </#if>
		            <#assign partyId = displayParty.partyId?default("_NA_")>
		            
		            <#-- begin of the data-->
		            <tr valign="middle"<#if alt_row> class="alternate-row"</#if>>
		              <#if orderInfo_index==0>
			              <td rowspan="${combineableOrderInfo.getSize()}">
			              	${combineableOrderInfo.key}
			              </td>
		              </#if>
		              <td><a href="/ordermgr/control/orderview?orderId=${orderHeader.orderId}" class='buttontext'>${orderHeader.orderId}</a></td>
		              <td align="right">${orderHeader.orderDate}</td>
		              <td align="right">${orh.getTotalOrderItemsQuantity()?string.number}</td>
		              <td align="right">${orderInfo.address1?if_exists} ${orderInfo.address2?if_exists}, <br/>${orderInfo.city?if_exists}, ${orderInfo.stateProvinceGeoId?if_exists}, ${orderInfo.countryGeoId?if_exists}</td>
		              <td align="right"><@ofbizCurrency amount=orderHeader.grandTotal isoCode=orh.getCurrency()/></td>
		
		              
		              <td>${statusItem.get("description",locale)?default(statusItem.statusId?default("N/A"))}</td>
		              </td>
		              <#if (requestParameters.filterInventoryProblems?default("N") == "Y") || (requestParameters.filterPOsOpenPastTheirETA?default("N") == "Y") || (requestParameters.filterPOsWithRejectedItems?default("N") == "Y") || (requestParameters.filterPartiallyReceivedPOs?default("N") == "Y")>
		                  <td>
		                      <#if filterInventoryProblems.contains(orderHeader.orderId)>
		                        Inv&nbsp;
		                      </#if>
		                      <#if filterPOsOpenPastTheirETA.contains(orderHeader.orderId)>
		                        ETA&nbsp;
		                      </#if>
		                      <#if filterPOsWithRejectedItems.contains(orderHeader.orderId)>
		                        Rej&nbsp;
		                      </#if>
		                      <#if filterPartiallyReceivedPOs.contains(orderHeader.orderId)>
		                        Part&nbsp;
		                      </#if>
		                  </td>
		              </#if>
		              <td>
		                <#if partyId != "_NA_">
		                  <a href="${customerDetailLink}${partyId}" class="buttontext">${partyId}</a>
		                <#else>
		                  ${uiLabelMap.CommonNA}
		                </#if>
		              </td>
		               <td>
			                 <input type="checkbox" class="${combineableOrderInfo.key}" name="${combineableOrderInfo.key}" value="${orderHeader.orderId}" onchange="javascript:toggleOrderIdList();"/>
			          </td>
		              <#if orderInfo_index==0>
			              <td rowspan="${combineableOrderInfo.getSize()}">
			              	<a class="buttontext combineBtn" href="javascript:void(0)" key="${combineableOrderInfo.key}">Combine them!</a>
			              </td>
		              </#if>
		            </tr>
		            <#-- toggle the row color -->
		            <#assign alt_row = !alt_row>
		          </#list>
				</#list>
	        <#else>
	          <tr>
	            <td colspan='4'><h3>${uiLabelMap.OrderNoOrderFound}</h3></td>
	          </tr>
	        </#if>
	        <#if lookupErrorMessage?exists>
	          <tr>
	            <td colspan='4'><h3>${lookupErrorMessage}</h3></td>
	          </tr>
	        </#if>
	      </table>
	    </form>
    </div>
</div>
<script>
$(function() {
	$('.combineBtn').click(function(){
		var e = $(this);
		var key = e.attr("key");
		var inputs = $('.' + key);
		var orderIds = '';
		$(inputs).each(function(i,c){
			c = $(c)
			if(c.attr("checked")=="checked") {
				orderIds = orderIds + (c.val()) + ', ';
			}
		});
		if(orderIds.length > 0) {
			alert(["Orders [" + orderIds + "] have been selected"]);
		} else {
			alert("No orders have been selected");
		}
	});
});
</script>